﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;

namespace WpfMesDemo2.Models
{
    public class ProductionOrder : INotifyPropertyChanged
    {
        private int _id;
        private string _orderId;
        private string _customer;
        private DateTime _orderDate;
        private DateTime _dueDate;
        private string _status;
        private bool _isDeleted;
        private ObservableCollection<Product> _products;

        public int Id
        {
            get => _id;
            set => SetField(ref _id, value);
        }

        public string OrderId
        {
            get => _orderId;
            set => SetField(ref _orderId, value);
        }

        public string Customer
        {
            get => _customer;
            set => SetField(ref _customer, value);
        }

        public DateTime OrderDate
        {
            get => _orderDate;
            set => SetField(ref _orderDate, value);
        }

        public DateTime DueDate
        {
            get => _dueDate;
            set => SetField(ref _dueDate, value);
        }

        public string Status
        {
            get => _status;
            set => SetField(ref _status, value);
        }

        public bool IsDeleted
        {
            get => _isDeleted;
            set => SetField(ref _isDeleted, value);
        }

        public ObservableCollection<Product> Products
        {
            get => _products;
            set => SetField(ref _products, value);
        }

        public event PropertyChangedEventHandler PropertyChanged;

        protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }

        protected bool SetField<T>(ref T field, T value, [CallerMemberName] string propertyName = null)
        {
            if (EqualityComparer<T>.Default.Equals(field, value))
                return false;

            field = value;
            OnPropertyChanged(propertyName);
            return true;
        }

        public ProductionOrder()
        {
            Products = new ObservableCollection<Product>();
        }
    }
}
